package com.REPDPMSystem.Service.Handler;

import com.REPDPMSystem.Mapper.CustomerMapper;
import com.REPDPMSystem.Service.CustomerService;
import com.REPDPMSystem.Entity.Customer;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;
@Service
public class CustomerHandler extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
    @Override
    public List<Customer> getCutomerInfo() {
        return baseMapper.selectList(null);
    }

    @Override
    public List<Customer> getCutomerInfo(String name) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("customer_organization_I",name);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<Customer> getCustomerInfo(String organizationI, String organizationII) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("customer_organization_I",organizationI);
        wrapper.eq("customer_organization_II",organizationII);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public boolean createCutomerInfo(Customer customer) {
        customer.setCustomer_id(UUID.randomUUID().toString());
        return baseMapper.insert(customer)>0;
    }

    @Override
    public boolean changeCutomerInfo(Customer customer) {
        return baseMapper.updateById(customer)>0;
    }
}
